package com.mooc;


import android.content.Context;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.baidu.cloud.videoplayer.bar.SimpleMediaController;
import com.baidu.cloud.videoplayer.widget.BDCloudVideoView;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;


/**
 * Created by Zirconi on 2017/6/24.
 */

public class BDPlayerViewManager extends SimpleViewManager<BDPlayerViewWithControllor> {

    private static String VIEW_NAME = "BDPlayerView";
    private static String mAK = "4502e77dbed14a73ab7e712d31398a88";
    private ThemedReactContext mContext;
    private BDCloudVideoView mBDPlayerView;


    @Override
    public String getName() {
        return VIEW_NAME;
    }


    @ReactProp(name = "source")
    public void setSource(BDPlayerViewWithControllor view, @Nullable String source) {
        BDCloudVideoView BCView = view.getBDPlayerView();
        BCView.setVideoPath(source);
        BCView.start();
    }

    @Override
    protected BDPlayerViewWithControllor createViewInstance(ThemedReactContext reactContext) {
        mContext = reactContext;
        BDCloudVideoView.setAK(mAK);
        BDPlayerViewWithControllor mBDPlayerView = new BDPlayerViewWithControllor(mContext);
        return mBDPlayerView;
    }
    // 资源drop时调用
    @Override
    public void onDropViewInstance(BDPlayerViewWithControllor view) {//对象销毁时

        super.onDropViewInstance(view);
        BDCloudVideoView BCView = view.getBDPlayerView();
        BCView.pause();
    }
}
